﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DevExpress.UserSkins;
using DevExpress.XtraBars.Helpers;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Ribbon.Gallery;
using System.Threading;
using System.Globalization;


namespace QLTV
{
    public partial class frmMain : RibbonBase
    {
        public frmMain()
        {

            InitializeComponent();


        }

        private void Main_Load(object sender, EventArgs e)
        {

            //load bonus skins
            GalleryDropDown g = new GalleryDropDown();
            g.Ribbon = ribbon;
            DevExpress.XtraBars.Helpers.SkinHelper.InitSkinGalleryDropDown(g);
            btnSkinSelector.DropDownControl = g;
            DevExpress.LookAndFeel.UserLookAndFeel.Default.StyleChanged += Default_StyleChanged;
            //minimize ribbon
            ribbon.Minimized = true;
            //load welcome
            lblWelcome.Caption = rm.GetString("sWelcome", myCultureInfo) + ":  " + Program.EmployeeName;

            loadBanLamViec();
        }
        private void Default_StyleChanged(object sender, EventArgs e)
        {
            QLTV.Database.dsUsersTableAdapters.tblUserProfileTableAdapter tadProfile = new Database.dsUsersTableAdapters.tblUserProfileTableAdapter();
            tadProfile.setDefautTheme(DevExpress.LookAndFeel.UserLookAndFeel.Default.SkinName, Program.username);

        }
        private void loadBanLamViec()
        {
            Forms.frmBanLamViec f = new Forms.frmBanLamViec();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            lblDateTime.Caption = (DateTime.Now.ToString("h:mm:ss tt, dd/MM/yyyy"));

        }

        private void btnDanhMuc_ItemClick(object sender, ItemClickEventArgs e)
        {


        }

        private void btnDanhSachNhanVien_ItemClick(object sender, ItemClickEventArgs e)
        {
            //Forms.HoSoNhanSu.frmDanhSachNhanSu f = new Forms.HoSoNhanSu.frmDanhSachNhanSu();
            //for (int i = 0; i < this.MdiChildren.Length; i++)
            //{
            //    if (f.Name == this.MdiChildren[i].Name)
            //    {
            //        this.MdiChildren[i].Activate();
            //        return;
            //    }
            //}
            //f.MdiParent = this;
            //f.Show();
        }

        private void btnThongTinCongTy_ItemClick(object sender, ItemClickEventArgs e)
        {
            //frmToChuc f = new frmToChuc();
            //f.Show();
        }

        private void frmMain_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnPhanQuyen_ItemClick(object sender, ItemClickEventArgs e)
        {
            frmPhanQuyen f = new frmPhanQuyen();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnBanLamViec_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e)
        {
            loadDanhMuc();
        }
        private void loadDanhMuc()
        {
            Forms.frmDanhMuc f = new Forms.frmDanhMuc();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnNguoiDung_ItemClick(object sender, ItemClickEventArgs e)
        {
            Forms.BaoMat.frmUserList f = new Forms.BaoMat.frmUserList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();

        }

        private void nbiVessel_ItemChanged(object sender, EventArgs e)
        {
            Forms.KhaiBao.frmVessel f = new Forms.KhaiBao.frmVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiVessel_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void nbiVesselType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmVesselType f = new Forms.KhaiBao.frmVesselType();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiFlag_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmFlag f = new Forms.KhaiBao.frmFlag();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiEngine_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //Forms.KhaiBao.frmEngine f = new Forms.KhaiBao.frmEngine();

            //for (int i = 0; i < this.MdiChildren.Length; i++)
            //{
            //    if (f.Name == this.MdiChildren[i].Name)
            //    {
            //        this.MdiChildren[i].Activate();
            //        return;
            //    }
            //}
            //f.MdiParent = this;
            //f.Show();
        }

        private void nbiEngineMaker_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmEngineMaker f = new Forms.KhaiBao.frmEngineMaker();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiEngineType_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmEngineType f = new Forms.KhaiBao.frmEngineType();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiThuyenVien_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCrewList f = new Forms.KhaiBao.frmCrewList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnDangXuat_ItemClick(object sender, ItemClickEventArgs e)
        {
            Application.Restart();
        }

        private void ribbon_Click(object sender, EventArgs e)
        {

        }

        private void navBarItem2_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCrewList f = new Forms.KhaiBao.frmCrewList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem6_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmVessel f = new Forms.KhaiBao.frmVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiGroupVessel_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmGroupVessel f = new Forms.KhaiBao.frmGroupVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiCertificate_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificatecs f = new Forms.KhaiBao.frmCertificatecs();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiCertificateCrew_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmCertificateCrew f = new Forms.KhaiBao.frmCertificateCrew();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiTrainingCourse_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmTrainingCourse f = new Forms.KhaiBao.frmTrainingCourse();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiTrainingCrew_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmTrainingPlan f = new Forms.KeHoach.frmTrainingPlan();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbiRanhk_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void nbiRanhk_LinkClicked_1(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmRank f = new Forms.KhaiBao.frmRank();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void nbi_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmContractList f = new Forms.KhaiBao.frmContractList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem7_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.frmBanLamViec f = new Forms.frmBanLamViec();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void btnBieuDoNS_ItemClick(object sender, ItemClickEventArgs e)
        {

        }

        private void btnInVinic_ItemClick(object sender, ItemClickEventArgs e)
        {
            QLTV.Reports.rpInVinic c = new Reports.rpInVinic();
            c.ShowPreview();
        }

        private void btnNotInVinic_ItemClick(object sender, ItemClickEventArgs e)
        {
            QLTV.Reports.rpNotInVinic c = new Reports.rpNotInVinic();
            c.ShowPreview();
        }

        private void btnTim_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {

        }

        private void nbiPhong_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {

        }

        private void barButtonItem1_ItemClick_1(object sender, ItemClickEventArgs e)
        {
            Reports.rptCrewList4 r = new Reports.rptCrewList4();
            r.ShowPreview();
        }

        private void barButtonItem9_ItemClick(object sender, ItemClickEventArgs e)
        {
            Reports.rptTongHop r = new Reports.rptTongHop();
            r.ShowPreview();
        }

        private void navBarItem4_ItemChanged(object sender, EventArgs e)
        {

        }

        private void navBarItem4_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            //Forms.KeHoach.frmLongPlanVessel f = new Forms.KhaiBao.frmLongPlanVessel();
            //f.Show();
        }

        private void navBarItem10_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KeHoach.frmKeHoach f = new Forms.KeHoach.frmKeHoach();
            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name && f.isLongPlan == false)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem11_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmPhongNghiepVu f = new Forms.KhaiBao.frmPhongNghiepVu();
            f.ShowDialog();
        }

        private void navBarItem12_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.BaoMat.frmUserList f = new Forms.BaoMat.frmUserList();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void navBarItem13_LinkClicked(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
        {
            Forms.KhaiBao.frmVessel f = new Forms.KhaiBao.frmVessel();

            for (int i = 0; i < this.MdiChildren.Length; i++)
            {
                if (f.Name == this.MdiChildren[i].Name)
                {
                    this.MdiChildren[i].Activate();
                    return;
                }
            }
            f.MdiParent = this;
            f.Show();
        }

        private void frmMain_MdiChildActivate(object sender, EventArgs e)
        {
            
        }



    }
}
